<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8" />
	<title>订单管理</title>
	<link rel="stylesheet" href="../css/common2.css" />
	<style>
		.search_img {
			position: absolute;
			margin-top: 1px;
			right: 3%;
		}

		td>div {
			white-space: pre-wrap;
			padding-left: 5px;
		}

		.search_img {
			position: absolute;
			right: 3%;
		}

		.other {
			height: 33px;
			border: 1px solid #7a7a7a;
		}

		#startTime,
		#endTime {
			margin-top: -50px;
		}

		input {
			padding-left: 5px;
		}

		.hut_but_tz {
			display: inline-block;
			height: 38px;
			width: 108px;
			line-height: 38px;
			padding: 0 18px;
			background: url(../image/enter.png) no-repeat center center;
			color: #fff;
			white-space: nowrap;
			text-align: center;
			font-size: 14px;
			border: none;
			border-radius: 2px;
			cursor: pointer;
		}
		/* .table1{
			white-space: wrap !important;
			
		} */
		td {
    max-width: 180px; /* 限制单元格最大宽度 */
    word-wrap: break-word; /* 启用单词换行 */
    white-space: normal; /* 允许正常换行 */
    text-overflow: ellipsis; /* 超出显示省略号 */
    overflow: hidden; /* 隐藏超出部分 */
}
.table1 {
    max-width: 200px; 
    white-space: wrap;
    word-wrap: break-word;
    overflow: hidden;
}

	</style>
</head>

<body>
	<div id="vue-root" style="margin-top: 50px">
		<div class="refresh" onclick="location.reload()">刷新</div>
		<!-- <div class="hut_but_tz" @click="print()">打印订单</div> -->
		<select class="search" style="position: absolute; right: 600px" v-model="search.schoolId">
			<option :value="undefined">请选择校区</option>
			<option v-for="school in schools" :key="school.id" :value="school.id" v-text="school.name"></option>
		</select>
		<input class="other" placeholder="请输入姓名" v-model="search.studentName" @keyup.enter="getData0"
			style="width: 145px; position: absolute; right: 430px" />
			<select class="search" style="position: absolute; right: 280px" v-model="search.courseId">
				<option :value="undefined">请选择课程</option>
				<option v-for="course in coursess" :key="course.id" :value="course.id" v-text="course.name"></option>
			</select>
		<input class="other" placeholder="请输入订单号" v-model="search.tradeNo" @keyup.enter="getData0"
		style="position: absolute; right: 100px" />
		<input placeholder="开始时间" class="other" id="startTime" v-model="search.startTime"
			style="width: 65px; font-size: 12px; position: absolute; right: 170px" />
		<input placeholder="结束时间" class="other" id="endTime" v-model="search.endTime" style="
          width: 65px;
          font-size: 12px;
          position: absolute;
          right: 100px;
          border-left: none;
        " />
		<img src="../image/search.png" height="35" width="35" class="search_img" @click="getData0" />
		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th>
							<input type="checkbox" class="check-box" v-model="all" />序号
						</th>
						<th>订单号</th>
						<th>校区</th>
						<th>订单类型</th>
						<th>学生/手机号</th>
						<th>购买项目</th>
						<th>总价</th>
						<th>应收</th>
						<th>实收</th>
						<th>查看订单详情</th>
						<th>业绩归属人</th>
						<th>经办人</th>
						<th>订单生成日期</th>
						<th>订单来源</th>
						<th class="table1">备注</th>
						<th>状态</th>
						<!-- <th>删除</th> -->
						<th>退款</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(order,index) in list" :key="order.id">
						<td>
							<input type="checkbox" class="check-box" v-model="order.checked" />{{index+1}}
						</td>
						<!-- <td>{{index+1}}</td> -->
						<td v-text="order.tradeNo"></td>
						<td v-text="order.schoolName"></td>
						<td v-text="order.way === 7 ? '线上' : (order.way === 11 ? '线下' : '')"></td>
						<td>
							<div v-text="order.personName"></div>
							<div v-text="order.phone"></div>
						</td>
						<td v-text="formatCourseNames(order.courseNames)"></td>
						<td v-text="order.orderPrice/100"></td>
						<td v-text="order.fee/100"></td>
						<td v-text="order.fee/100"></td>
						<td>
							<a :href="'/order_details.html?id='+order.id" class="btn" style="padding: 8px 16px; background-color: #69bbf4; color: white; text-decoration: none; border-radius: 4px;">查看</a>
						</td>
						<td v-text="order.staffUserName"></td>
						<td v-text="order.handleUser"></td>
						<td v-text="order.time"></td>
						<td>机构创建</td>
						<td class="table1" v-text="order.remark"></td>
						<td v-text="order.refund === 0 ? '已支付' : '已退款'"></td>
						<td style="border-left: none; margin-top: 1px;">
							<div>
								<div class="delete-icon option-icon" v-if="able.del"  style="display: inline-block;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" @click="del([order.id])" />
								</div>
								<div class="refund-icon option-icon" style="display: inline-block;">
									<button @click="confirmRefund(order.id)">退款</button>
								</div>
							</div>
						</td>
						
						
					</tr>
				</tbody>
			</table>
		</div>
		
		<div class="delete" @click="batchDelete" v-if="able.del&&total>1">批量删除</div>
		<div class="delete" v-if="able.export" @click="exports">导出</div>
		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>
		<div style="float: right;">
			总共{{total}}条记录
			<select class="ui-select init" style="height:32px" v-model="pageSize">
				<option :value="10">每页10条</option>
				<option :value="30">每页30条</option>
				<option :value="100">每页100条</option>
			</select>
		</div>
	</div>
	

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/lib/laydate/laydate.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>
		var agentId = top_params().id;
		

		var app = new Vue(
			merge({
				data: {
					urls: {
						del: "/pc/order/del",
						list: "/pc/order/list?agentId=" + agentId,
					},
					coursess: [],
					schools:[]
				},
				created: function () {
					abled('order', this);
					this.getData();
					axios.get("/pc/course/all/" + agentId).then(
						function (res) {
							this.coursess = res.data;
						}.bind(this)
					);
					axios.get("/pc/school/all/" + agentId).then(
						function (res) {
							this.schools = res.data;
						}.bind(this)
					);
				},
				methods: {
					formatCourseNames(names) {
    return names.join(', ');
  },
					exports: function () {
						var q = Qs.stringify(this.search);
						if (q) q = "&" + q;
						location.href = "/pc/order/export?agentId=" + agentId + q;
					},
					confirmRefund(orderId) {
						if (confirm("确认要退款吗？")) {
							// // 用户点击了确认，调用退款接口
							// this.refund(orderId);
							location.href = '/refund_details.html?id=' + orderId;
							
						}
					},
					refund(orderId) {
						axios
							.post("/pc/order/refund/" + orderId)
							.then((response) => {
								if (response.data.code === -1) {
									alert("退款失败: " + response.data.msg);
								}else{
									alert("退款成功");
								}
								// 处理退款成功的逻辑
								
							})
							.catch((error) => {
								// 处理退款失败的逻辑
								alert("退款失败", error);
							});
					},
				},
			})
		);

		["startTime", "endTime"].forEach(function (it) {
			laydate.render({
				elem: "#" + it,
				type: "datetime",
				done: function (value, date, endDate) {
					app.search[it] = value;
				},
			});
		});
	</script>
</body>

</html>